package com.glsc.ngateway.common.base.repo.mysql.opmanage.report.subscribe;

import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.subscribe.UserReportSubscribeTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
import java.time.LocalDateTime;

/**
 * @author: qiyr
 * @date: 2022/6/9 17:09
 * @description: 用户报表订阅任务数据访问层
 */
@Repository
public interface UserReportSubscribeTaskRepo extends JpaRepository<UserReportSubscribeTask, BigInteger>, JpaSpecificationExecutor<UserReportSubscribeTask> {

    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query(value = "UPDATE glsc_data.t_user_report_subscribe_task SET update_time=:updateTime WHERE id=:id", nativeQuery = true)
    void updateTime(@Param("id") BigInteger id, @Param("updateTime") LocalDateTime updateTime);

    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query(value = "UPDATE glsc_data.t_user_report_subscribe_task SET task_status=:status WHERE id=:id", nativeQuery = true)
    void updateStatus(@Param("id") BigInteger id, @Param("status") String status);
}
